package br.usp.poli.coop8.magapkg;

import java.io.Serializable;
import java.sql.Date;
import java.util.Set;
import javax.persistence.Embeddable;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.OneToMany;

@Entity
public class Publicacao implements Serializable {
	@EmbeddedId
	private Publicacao.PK pk;

	private String categoria;

	private String nome;

	private int numexemplares;

	private int ranking;

	private String sinopse;

	@OneToMany(mappedBy="publicacao")
	private Set<Exemplar> exemplarCollection;

	@OneToMany(mappedBy="publicacao")
	private Set<Lista> listaCollection;

	private static final long serialVersionUID = 1L;

	public Publicacao() {
		super();
	}

	public Publicacao.PK getPk() {
		return this.pk;
	}

	public void setPk(Publicacao.PK pk) {
		this.pk = pk;
	}

	public String getCategoria() {
		return this.categoria;
	}

	public void setCategoria(String categoria) {
		this.categoria = categoria;
	}

	public String getNome() {
		return this.nome;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}

	public int getNumexemplares() {
		return this.numexemplares;
	}

	public void setNumexemplares(int numexemplares) {
		this.numexemplares = numexemplares;
	}

	public int getRanking() {
		return this.ranking;
	}

	public void setRanking(int ranking) {
		this.ranking = ranking;
	}

	public String getSinopse() {
		return this.sinopse;
	}

	public void setSinopse(String sinopse) {
		this.sinopse = sinopse;
	}

	public Set<Exemplar> getExemplarCollection() {
		return this.exemplarCollection;
	}

	public void setExemplarCollection(Set<Exemplar> exemplarCollection) {
		this.exemplarCollection = exemplarCollection;
	}

	public Set<Lista> getListaCollection() {
		return this.listaCollection;
	}

	public void setListaCollection(Set<Lista> listaCollection) {
		this.listaCollection = listaCollection;
	}


	@Embeddable
	public static class PK implements Serializable {
		private String idpublicacao;
		private Date dataexemplar;
		private static final long serialVersionUID = 1L;

		public PK() {
			super();
		}

		public String getIdpublicacao() {
			return this.idpublicacao;
		}

		public void setIdpublicacao(String idpublicacao) {
			this.idpublicacao = idpublicacao;
		}

		public Date getDataexemplar() {
			return this.dataexemplar;
		}

		public void setDataexemplar(Date dataexemplar) {
			this.dataexemplar = dataexemplar;
		}

		@Override
		public boolean equals(Object o) {
			if (o == this) {
				return true;
			}
			if ( ! (o instanceof PK)) {
				return false;
			}
			PK other = (PK) o;
			return this.idpublicacao.equals(other.idpublicacao)
				&& this.dataexemplar.equals(other.dataexemplar);
		}

		@Override
		public int hashCode() {
			return this.idpublicacao.hashCode()
				^ this.dataexemplar.hashCode();
		}

	}

}
